package com.llz.leaveApply;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.function.Predicate;
import java.util.stream.Collectors;


public class Person {
    String name;
    int age;
    int score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public Person(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    abstract static class Myfilter implements Predicate {
//    Person person;
//        public  Myfilter(Person person){
//         this.person=person;
//     };

        abstract boolean filter(Person a);


    }

    //    定一个Person 类 name age 数组 ArryList存储 10个；
//
//
    public static void main(String[] args) {
        ArrayList<Person> personArrayList = new ArrayList<>();
        Random random = new Random();
//生成10个人存到Arraylist;
        for (int i = 0; i < 10; i++) {
            Person person = new Person("aaa" + i, 17 + random.nextInt(5), 80 + random.nextInt(20));
            personArrayList.add(person);
        }
//        1 使用Stream Api 提供的Lamdaba 表达式过滤年龄大于18的学生
//        过滤到新的链表中
        List<Person> newPersonList = new ArrayList<>();
        newPersonList = personArrayList.stream().filter(item -> item.age < 18).collect(Collectors.toList());
        System.out.println("方法1结束");

//2 匿名内部类
//      personArrayList.removeIf(new Predicate(){
//            @Override
//            public boolean test(Object o) {
//                Person p=(Person) o;
//                return p.getAge()<18?false:true;
//            }
//
//        });

        System.out.println(personArrayList);


        for (int j = 0; j < personArrayList.size(); j++) {
            for (int i = 0; i < personArrayList.size() - 1; i++) {
                Person temp;



                    temp = personArrayList.get(i);
                    personArrayList.set(i, personArrayList.get(i + 1));
                    personArrayList.set(i + 1, temp);


                }
            }

        }


    }



class myCompare implements Comparator{

    @Override
    public int compare(Object o1, Object o2) {
        return 0;
    }
}













